import { listConfig } from "@/api/system/config";
export default {
  namespaced: true,
  state: {
    // 无操作计时时间
    lockTime: 0,
    screenSavertime: sessionStorage.getItem('screenSavertime'),//锁屏时间
    // 当前是否为锁屏状态
    isLock: sessionStorage.getItem('isLock') || 'false',
  },
  mutations: {
    updatelockTime(state, lockTime) {
      state.lockTime = lockTime;
    },

    updateisLock(state, isLock) {
      state.isLock = isLock
      sessionStorage.setItem('isLock', isLock)
    },
    setscreenSavertime: (state, screenSavertime) => {
      state.screenSavertime = screenSavertime
      sessionStorage.setItem('screenSavertime', screenSavertime)
    },
  },
  actions: {
    // 获取密码和时间
    SavertimePasswd({ commit }) {
      return new Promise(resolve => {
        // 向后端请求
        listConfig({ configKey: "sys.terminal.time" }).then(response => {
          let curscreenSavertime = response.rows && response.rows.length && (response.rows[0].configValue) * 60 || 600;
          commit('setscreenSavertime', curscreenSavertime)
          resolve(curscreenSavertime)
        })
      })
    },
  }
}
